<template>
	<el-container v-if="isAlready">
		<el-header>
			<div class="left-panel">
				<fsButton ref="button" plain size="small" :buttons="buttons" @clickHandler="buttonHandler"></fsButton>
			</div>
			<div class="right-panel">
				<ex-search ref="search" :searches="searches" @searchOk="searchHandler" :fixedParam="fixedParams"
						   default-code="code" placeholder="请输入房产编码"></ex-search>
			</div>
		</el-header>
		<el-main class="nopadding" style="padding: 0 5px;">
			<ex-table ref="table" :columns="columns" :url="this.$API.asset.assetLog.list.url"
					  :refs="this.$refs" search="search" @columnClick="columnClickHandler">
			</ex-table>
		</el-main>
	</el-container>
	<data-card ref="dataCard"></data-card>
</template>

<script>
	import ExTable from "@/components/exTable/index.vue";
	import ExSearch from "@/components/exSearch/index.vue";
	import tool from "@/utils/tool";
	import DataCard from "@/views/asset/card/card.vue";
	import BaseTemplate from "@/utils/baseTemplate";

	export default {
		name: '房产出租查询报表',
		components: {DataCard, ExTable, ExSearch},
		data() {
			return {
				dialog: {
					save: false,
					permission: false,
				},
				apiObj: [],
				buttons: [
					{name: "导出", icon: "el-icon-download", click: "export",  type: "info"},
				],
				searches: [],
				columns: [
					{code: "documentInfo.code", name: "单据编码", width:"135"},
					{code: "changeAfter.code", name: "房产编码", width:"135",click:"show1"},
					{code: "changeAfter.financialCode", name: "财务编码", width:"170"},
					{code: "changeAfter.name", name: "房产名称", width:"200"},
					{code: "changeAfter.assetCategoryId", name: "资产分类",width:"120", formatter:"DICT",key: "FamsAssetCategory"},
					{code: "financialType", name: "财务类型", width:"70",formatter: function(row){
							if(row.changeAfter.financialCode){
								return "账内";
							}
							return "账外";
					}},
					{code: "changeAfter.other.houseType", name: "房产类型", width:"", formatter:"DICT",key: "houseType"},
					{code: "changeAfter.other.city", name: "所在城市", width:""},
					{code: "changeAfter.other.address", name: "坐落地址", width:"200"},
					{code: "changeAfter.usingDepartmentId", name: "使用部门", width:"100",formatter: "DICT",key: "SysOrganization"},
					{code: "changeAfter.usingMenId", name: "使用人", width:"100",formatter: "DICT",key: "SysUser"},
					{code: "changeAfter.dutyDepartmentId", name: "管理部门", width:"100",formatter: "DICT",key: "SysOrganization"},
					{code: "changeAfter.other.area", name: "建筑面积", width:""},
					{code: "changeAfter.other.useArea", name: "使用面积", width:""},
					{code: "changeAfter.other.houseNumber", name: "房产权证证号", width:"200"},
					{code: "changeAfter.other.houseUseName", name: "房产权证产权人名称", width:"200"},
					{code: "changeAfter.other.houseLandNumber", name: "土地证证号", width:"150"},
					{code: "changeAfter.other.houseLandUseName", name: "土地证产权人名称", width:"200"},
					{code: "changeAfter.other.houseImmobilityNumber", name: "房地产权证证号", width:"200"},
					{code: "changeAfter.other.houseImmobilityUseName", name: "房地产权人名称", width:"200"},
					{code: "changeAfter.other.contractLesseeUnit", name: "承租单位", width:"200"},
					{code: "contractDate", name: "租赁期限", width:"300", formatter:  function(row){
							if(row.changeAfter.other.contractStartDate && row.changeAfter.other.contractEndDate){
								let startDate = tool.format.convert(row.changeAfter.other.contractStartDate, "DATE", null);
								let endDate = tool.format.convert(row.changeAfter.other.contractEndDate, "DATE", null);
								return startDate+"～"+endDate;
							}
							return null;
						}},
					{code: "changeAfter.other.contractLeaseArea", name: "租用面积", width:"150"},
					{code: "changeAfter.other.contractIncome", name: "年租赁收益", width:"200"},
					{code: "changeAfter.other.occupyUnit", name: "占用单位", width:"150"},
					{code: "changeAfter.other.occupyArea", name: "占用面积", width:"150"},
					{code: "changeAfter.other.rentedArea", name: "已出租面积", width:"150"},
					{code: "changeAfter.other.selfArea", name: "自用面积", width:"150"},
					{code: "changeAfter.other.idleArea", name: "闲置面积", width:"150"},
					{code: "changeAfter.other.transferredNotOwnership", name: "已转让未过户", width:"200"},
					{code: "changeAfter.other.specialDescription", name: "特别情况说明", width:"200"},
				],
				parentLevelCode:"",
				assetcategoryIds:[],
				fixedParams: {},
				isAlready: false,
				readDeptIds: this.$TOOL.current.readDeptIds(),
				// manageDeptIds: this.$TOOL.current.manageDeptIds(),
				manageAssetCategoryIds: this.$TOOL.current.manageAssetCategoryIds(),
				loginUser: tool.current.user(),
			}
		},
		async created() {
			await this.getFcAssetCategoryIds();
			this.searches = [
				{type: "input", name: "房产编码", code: "code", placeholder: "请输入房产编码", maxlength: 30, showLimit: true},
				{type: "input", name: "房产名称", code: "name", placeholder: "请输入房产名称"},
				{type: "input", name: "所在城市", code: "city", placeholder: "请输入所在城市"},
				{type: "tree-select", name: "资产分类", code: "assetCategoryIds", placeholder: "请选择资产分类",dictCode:'FamsAssetCategory',checkStrictly:true,multiple:true,dataPermissionProcess:true,permissionData:this.assetcategoryIds},
				{type: "tree-select", name: "管理部门", code: "dutyDepartmentIds",dictCode:'SysOrganization',checkStrictly:true,multiple:true,dataPermissionProcess:true,permissionData:this.$TOOL.current.readDeptIds()},
				{type: "tree-select", name: "使用部门", code: "usingDepartmentIds",dictCode:'SysOrganization',checkStrictly:true,multiple:true,dataPermissionProcess:true,permissionData:this.$TOOL.current.readDeptIds()},
				{type: "select", name: "使用信息", code: "houseUsing", placeholder: "请选择使用信息", dictCode:'HOUSE_USING'},
			]
			this.fixedParams.documentStatus = 'executed';
			this.fixedParams.documentType = "use";
			this.fixedParams.deptIds = this.readDeptIds;
			this.isAlready = true;
		},
		mounted() {
		},
		methods: {
			buttonHandler(index, name) {
				this.$options.methods[name](this, index);
			},
			async getFcAssetCategoryIds() {
				let queryParams = {}
				queryParams.mainCategoryCode = 'fc';
				let res = await this.$API.asset.assetcategory.listData.post(queryParams);
				if(res.code === 2000 && res.data && res.data.length > 0){
					this.assetcategoryIds = res.data.map(item => item.id);
				}
			},
			async searchHandler() {
				let queryParams = {}
				await this.$refs.table.refresh(queryParams);
			},
			columnClickHandler(name, data) {
				this.$options.methods[name](this, data);
			},
			formaterQueryParams(queryParams,_this){
				Object.assign(queryParams, _this.$refs.search.searchParams());
			},
			//查看
			async show1(_this, row) {
				let assetCategory = await _this.$cache.data.loadAssetCategory(row.changeAfter.assetCategoryId);
				try {
					_this.loading = true;
					let entity = {cardId: assetCategory.assetCardId, _editFlag: false}
					_this.$nextTick(() => {
						_this.cardPreview = false;
						_this.$refs.dataCard.open(Object.assign(entity, row.changeAfter));
					});
				} finally {
					_this.loading = false;
				}
			},
			//导出
			async export(_this,index) {
				_this.$refs.button.loading(index,true);
				let queryPrams = {
				};
				queryPrams.exportType = "usingHouse";
				queryPrams.needOrderBy = true;
				Object.assign(queryPrams, _this.$refs.search.searchParams());
				let exportApi = _this.$API.asset.assetLog.export;
				let exTableRef = _this.$refs.table;
				let exportBtnRef = _this.$refs.button;
				let exportBtnIndex = index;
				await BaseTemplate.export(_this, exportApi, queryPrams, exportBtnRef, exportBtnIndex, exTableRef);
				_this.$refs.button.loading(index,false);
			},
		}
	}

</script>

<style scoped>

</style>
